package com.yun.algorithmproblem.leetcode;

public class Leetcode2275 {

    public static void main(String[] args) {
        Leetcode2275 obj = new Leetcode2275();
        int[] candidates=new int[]{16,17,71,62,12,24,14};
        System.out.println(obj.largestCombination(candidates));
    }

    public int largestCombination(int[] candidates) {
        int maxVal=0;
        for (int candidate : candidates) {
            maxVal=Math.max(maxVal,candidate);
        }
        int maxLength=Integer.toBinaryString(maxVal).length();
        int[] bitCount=new int[maxLength];
        for (int candidate : candidates) {
            String binaryString = Integer.toBinaryString(candidate);
            for (int i = 0; i < binaryString.length(); i++) {
                if(binaryString.charAt(binaryString.length()-1-i)=='1'){
                    bitCount[i]++;
                }
            }
        }
        int ans=0;
        for (int i : bitCount) {
            ans=Math.max(ans,i);
        }
        return ans;
    }
}
